<template>
  <div>
    <el-form :model="candidate" :rules="rules" ref="candidateForm" label-width="120px">
      <el-form-item label="面试岗位" prop="jobId">

        <el-select v-model="candidate.jobId" placeholder="请选择">
          <el-option
              v-for="item in jobList"
              :key="item.id"
              :label="item.jobName"
              :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="姓名" prop="realName">
        <el-input v-model="candidate.realName"></el-input>
      </el-form-item>
      <el-form-item label="身份证号码" prop="identityNum">
        <el-input v-model="candidate.identityNum"></el-input>
      </el-form-item>
      <el-form-item label="性别" prop="sex">
        <el-select v-model="candidate.sex" placeholder="请选择性别">
          <el-option label="男" value="1"></el-option>
          <el-option label="女" value="0"></el-option>

        </el-select>
      </el-form-item>
      <el-form-item label="手机号" prop="mobile">
        <el-input v-model="candidate.mobile"></el-input>
      </el-form-item>
      <el-form-item label="邮箱" prop="email">
        <el-input v-model="candidate.email"></el-input>
      </el-form-item>
      <el-form-item label="出生日期" prop="birthday">
        <el-date-picker v-model="candidate.birthday" type="date" placeholder="请选择出生日期"></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm">立即提交</el-button>
        <el-button @click="resetForm">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import axios from 'axios'
export default {
  data() {
    return {

      jobList:[],
      candidate: {

      },
      rules: {
        jobId: [
          { required: true, message: '请选择面试岗位', trigger: 'change' }
        ],
        realName: [
          { required: true, message: '请输入姓名', trigger: 'blur' }
        ],
        identityNum: [
          { required: true, message: '请输入身份证号码', trigger: 'blur' }
        ],
        sex: [
          { required: true, message: '请选择性别', trigger: 'change' }
        ],
        mobile: [
          { required: true, message: '请输入手机号', trigger: 'blur' }
        ],
        email: [
          { required: true, message: '请输入邮箱', trigger: 'blur' }
        ],
        birthday: [
          { required: true, message: '请选择出生日期', trigger: 'change' }
        ]
      }
    };
  },

  mounted(){
    axios.get('http://localhost:8781/job/listJob').then(res=>{
      this.jobList=res.data.data
    })
  },
  methods: {
    submitForm() {
      this.$refs.candidateForm.validate((valid) => {


        if (valid) {

          axios.post('http://localhost:8781/candidate/add', this.candidate).then(res=>{
            console.log(res)
            if(res.data.code==200){
              this.$message.success(res.data.msg);
              this.$router.push('/candidateList');
            }else{
              this.$message.error(res.data.msg);
            }
          })
          // 这里可以添加提交表单数据的逻辑，例如发送axios请求
          console.log('表单提交成功', this.candidate);
        } else {
          console.log('表单验证失败');
          return false;
        }
      });
    },
    resetForm() {
      this.$refs.candidateForm.resetFields();
    }
  }
};
</script>

<style scoped>
</style>